#------------------------------------------------------------------------------
# Figure 6. # predicted versus observed
# see PI_models_prediction_multilevel.do for the numbers reported here
#==============================================================================

# manual input
coef3 <-NULL 
coef3 <- rbind(coef3,c(1.75, 1.63, 1.88))
coef3 <- rbind(coef3,c(1.26, 1.16, 1.36))
coef3 <- rbind(coef3,c(1.74, 1.63, 1.85))
coef3 <- rbind(coef3,c(1.17, 1.07, 1.26))

coef6 <-NULL 
coef6 <- rbind(coef6,c(2.41, 2.28, 2.53))
coef6 <- rbind(coef6,c(1.38, 1.25, 1.50))
coef6 <- rbind(coef6,c(2.31, 2.20, 2.41))
coef6 <- rbind(coef6,c(1.39, 1.25, 1.52))

#------------------------------------------------------------------------------
# when capping network size at 3 
#==============================================================================

coef <- coef3 

pdf(here('results','figures',"TESS_prediction_size3.pdf"),paper="special",width=6,height=4)
layout(matrix(1:2,1,2))

mean <- coef[1:2,1]
lci  <- coef[1:2,2]
uci  <- coef[1:2,3]

barCenters = barplot(mean, col=c("gray","skyblue"),ylim=c(0,2.5),xpd = FALSE,
	names.arg=c("Prediction","Observed"),ylab="Mean Network Size with 95% intervals",
	main="Important Matters") 
arrows(barCenters,lci,barCenters,uci,
	lwd = 1.5, angle = 90,code = 3, length = 0.05)
abline(h=0,lty=2)

mean <- coef[1:2+2,1]
lci  <- coef[1:2+2,2]
uci  <- coef[1:2+2,3]

barCenters = barplot(mean, col=c("gray","pink"),ylim=c(0,2.5),xpd = FALSE,
	names.arg=c("Prediction","Observed"),ylab="Mean Network Size with 95% intervals",
	main="Political Matters") 
arrows(barCenters,lci,barCenters,uci,
	lwd = 1.5, angle = 90,code = 3, length = 0.05)
abline(h=0,lty=2)
dev.off()

#------------------------------------------------------------------------------
# without capping
#==============================================================================

coef <- coef6
pdf(here('results','figures',"TESS_prediction_size6.pdf"),paper="special",width=6,height=4)
layout(matrix(1:2,1,2))

mean <- coef[1:2,1]
lci  <- coef[1:2,2]
uci  <- coef[1:2,3]

barCenters = barplot(mean, col=c("gray","skyblue"),ylim=c(0,2.8),xpd = FALSE,
	names.arg=c("Prediction","Observed"),ylab="Mean Network Size with 95% intervals",
	main="Important Matters") 
arrows(barCenters,lci,barCenters,uci,
	lwd = 1.5, angle = 90,code = 3, length = 0.05)
abline(h=0,lty=2)

mean <- coef[1:2+2,1]
lci  <- coef[1:2+2,2]
uci  <- coef[1:2+2,3]

barCenters = barplot(mean, col=c("gray","pink"),ylim=c(0,2.8),xpd = FALSE,
	names.arg=c("Prediction","Observed"),ylab="Mean Network Size with 95% intervals",
	main="Political Matters") 
arrows(barCenters,lci,barCenters,uci,
	lwd = 1.5, angle = 90,code = 3, length = 0.05)
abline(h=0,lty=2)

dev.off()